// Paint

var NewComponent = null
var SelectComponent = null
var selectObj = null
// init
NewComponent = Qt.createComponent("New.qml")
SelectComponent = Qt.createComponent("Select.qml")
checkComponent(NewComponent)
checkComponent(SelectComponent)

function checkComponent(component)
{
    function componentLoaded()
    {
        if (component.status !== Component.Ready)
            console.error(
                        "Failed to load " + component.url + " : " + component.errorString(
                            ))
    }

    if (component.status === Component.Loading)
        component.statusChanged.connect(componentLoaded)
    else
        componentLoaded()
}

function newPost()
{
    selectObj = SelectComponent.createObject(mainRoot, {"anchors.fill":mainRoot})
    selectObj.selected.connect(onSelected)
}

function onSelected()
{
    var path = selectObj.fileUrl
    selectObj.destroy()
    var newObj = NewComponent.createObject(mainRoot,
                                           {
                                               "anchors.fill":mainRoot,
                                               source : path
                                           })
}


